﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace testgame
{
    /// <summary>
    /// monster类
    /// </summary>
    class monster
    {
        //声明怪兽图片
        Image monster1;
        Image monster2;
        Image monster3;
        public Image monsterImg;

        private const int SpeedX = 10;//怪兽移动速度
        public int _x = 0;//怪兽图片移动起始的坐标x
        public int _y = 0;//怪兽图片移动起始的坐标y
        public static List<monster> monsters = new List<monster> ();//敌机对象列表
        private int mo;//怪兽图片索引
        List<Image> imgList = new List<Image>();//怪兽图片列表
        public bool flag = false;//碰撞的标志

        public monster()
        { }



        //初始化怪兽所在矩形
        public monster(int y,int mos)
        {
            _y = y;//横坐标
            mo = mos;
            monster1 = Properties.Resources.怪兽1;
            monster2 = Properties.Resources.怪兽2;
            monster3 = Properties.Resources.怪兽3;

            //使怪兽随机出现
            switch (mo)
            {
                case 0:
                    monsterImg = monster1 ; break;
                case 1:
                    monsterImg = monster2 ; break;
                case 2:
                    monsterImg = monster3 ; break;
                default:
                    break;
            }
            imgList.Add(monster1);
            imgList.Add(monster2);
            imgList.Add(monster3);


        }
        
        //得到怪物坐标location
        public Point GetLoc()
        {
            Point p = new Point();
            p.X = this._x;
            p.Y = this._y;
            return p;
        }
        
        /// <summary>
        /// 随机位置产生随机的怪物
        /// </summary>
        public static void ProduceMonster()
        {
            Random rad = new Random();
            if (rad.Next(30) == 0)
            {
                monster  m = new monster(rad.Next(10, 120), rad.Next(0, 3));
                monsters.Add(m);
            }
        }
        /// <summary>
        /// 出现怪兽
        /// </summary>
        public void MonsterShow(Graphics g)
        {
            g.DrawImage(monsterImg, _x, _y,100,100);
        }

        //一个怪兽的移动
        public void mMove()
        {
            _x += SpeedX ;
        }



        /// <summary>
        /// 一群怪兽移动函数
        /// </summary>
        public static void monsterMove(Graphics g)//通过定时位置让图片发生偏移
        {
            for (int i = 0; i < monsters.Count; i++)
            {
                monsters[i].MonsterShow(g);
                monsters[i].mMove();
                if (monsters[i]._y > 650)
                {
                    monsters.Remove(monsters[i]);
                }
            }
        }





    }
}
